package com.zy.service.crm.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.crm.CustomerInfoDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.crm.CustomerInfo;
import com.zy.pojo.query.crm.CustomerInfoQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.crm.CustomerInfoService;
import com.zy.utils.DateUtil;

@Service("customerInfoService")
public class CustomerInfoServiceImpl extends BaseServiceImpl<CustomerInfo> implements CustomerInfoService {

	@Autowired
	private CustomerInfoDao customerInfoDao;

	@Override
	public PageVo pageCustomerInfo(CustomerInfoQuery customerInfoQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.customerInfoDao.countCustomerInfo(customerInfoQuery), this.customerInfoDao.listCustomerInfo(customerInfoQuery, start, limit));
	}

	@Override
	public void saveCustomerInfo(CustomerInfo customerInfo) {
		long time = DateUtil.getTime();
		this.customerInfoDao.save(customerInfo);
	}
	
	@Override
	public void updateCustomerInfo(CustomerInfo customerInfo) {
		this.customerInfoDao.updateByPrimaryKeySelective(customerInfo);
	}

	@Override
	public void removeCustomerInfo(long id) {
		try {
			this.customerInfoDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			CustomerInfo customerInfo = new CustomerInfo();
			customerInfo.setId(id);
			this.customerInfoDao.updateByPrimaryKeySelective(customerInfo);
		}
	}

	@Override
	public void recover(long id) {
		CustomerInfo customerInfo = new CustomerInfo();
		customerInfo.setId(id);
		this.customerInfoDao.updateByPrimaryKeySelective(customerInfo);
	}

}
